# views.py: 路由，视图函数
# 蓝图
from flask import Blueprint,render_template,request,jsonify
from .models import *
blue = Blueprint('user',__name__)
# blue2 = Blueprint('product',__name__)
@blue.route('/')
def index1():
    return '<h1>index1</h1>'


# 前后端不分离: render_template('index.html',users=users)
# 前后端分离:
#       后端返回json字符串：jsonify()
#       前端使用AJAX来请求数据：Ajax

# jsonify()：序列化

# HTTP请求方式：
# GET: 获取数据
# POST: 新增数据
# PUT: 修改数据
# DELETE: 删除数据

@blue.route('/users/',methods=['GET','POST','PUT','DELETE'])
def users():
    if request.method == 'GET':
        return jsonify({'method':'GET'})
    elif request.method == 'POST':
        return jsonify({'method':'POST'})
    elif request.method == 'PUT':
        return jsonify({'method':'PUT'})
    elif request.method == 'DELETE':
        return jsonify({'method':'DELETE'})